function telReg(tel) {
  // /^1(3|4|5|6|7|8|9)\d{9}$/
  // phoneRegex: /^(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[5678]|19[8-9]|166)[0-9]{8}$/, // /^1\d{10}$/;
  if ((/^1[3-9]\d{9}$/.test(tel))) {
    return true
  } else {
    return false
  }
}

function formDate(timeStamp) {
  var date = new Date(timeStamp)
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate()
  m = m < 10 ? '0' + m : m
  d = d < 10 ? '0' + d : d
  return y + "-" + m + "-" + d
}

function processingTime() {
  let days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  var weeks = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
  // let date = new Date('2023-04-30')
  let date = new Date()
  var year = date.getFullYear();
  if ((year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0)) {
    days[1] = 29
  }
  let month = date.getMonth() + 1
  let day = date.getDate()
  let week = date.getDay()
  // console.log(week)
  // if(week == 7){
  //   week = 0
  // }
  for (let i = 0; i < days.length; i++) {
    if ((i + 1) == month) {
      if (day == days[i]) {
        day = 1
        if (month >= 12) {
          month = 1
        } else {
          month += 1
        }
        break
      }else{
        day += 1
        break
      }
    }
  }
  month = month < 10 ? '0' + month : month
  day = day < 10 ? '0' + day : day
  let str = `${month}月${day}日${weeks[week]}`
  // let str = `${month}月${day}日(${weeks[week]})`
  return str
}
// 获取当前日期与星期
function todayTime() {
  var today = new Date();
  var weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]
  // 获取年份
  // var year = today.getFullYear();
  // 获取月份(0-11)
  var month = today.getMonth() + 1;
  // 获取日(1-31)
  var day = today.getDate();
  // 获取周几(0-6，0 表示星期天)
  const dayOfWeek = today.getDay();
  month = month < 10 ? '0' + month : month
  day = day < 10 ? '0' + day : day
  let str = `${month}月${day}日${weeks[dayOfWeek]}`
  return str
}
// 商品失效售空排最后面
// 排序 从10-0
function objectSort(property) {
  return (obj1,obj2) => {
    return obj2[property]-obj1[property]
  }
}
// 排序 从0-10
function objectSortZ(property) {
  return (obj1,obj2) => {
    return obj1[property]-obj2[property]
  }
}
// 获取星期
function weekDay(time) {
  const weekNum = new Date(time).getDay();
  let week = "";
  switch (weekNum) {
      case 0:
          week = "周日";
          break;
      case 1:
          week = "周一";
          break;
      case 2:
          week = "周二";
          break;
      case 3:
          week = "周三";
          break;
      case 4:
          week = "周四";
          break;
      case 5:
          week = "周五";
          break;
      case 6:
          week = "周六";
          break;
  }
  return week;
};

module.exports = {
  telReg: telReg,
  formDate: formDate,
  processingTime: processingTime,
  todayTime: todayTime,
  objectSort: objectSort,
  objectSortZ: objectSortZ,
  weekDay: weekDay,
}